<?php
/**
 * sina用户表数据操作层
 * @author yangchao
 */

class db_love_request extends db_base {
    
	var $table_name = "love_request";
	
	function db_user_info()
	{
		parent::db_base();
	}
	
	/**
	 * 前台取用户信息
	 * @param $uid
	 */
	function get_item_by_id($id)
	{
		$mc = mem_cache::get_instance();
		$key = CACHE_PREFIX_USER_ITEM;
		$cache = $mc->get($key);
		if ($cache === false)
		{
			$content = $this->get_alllist($this->table_name,1,1,"","id='{$id}' and status=1");
			// 保存MC
			$mc->set($key, serialize($content), 0, CACHE_TIME_USER_ITEM);
		}
		else
		{
			$content = unserialize($cache);
		}
		
		return $content[0];
		
	}
	
	
	/**
	 * 插入请求数据
	 */
	function insert_love_request($request_uid,$answer_uid,$request_name,$answer_name)
	{
		// 插入数据
		$ary = array();
		$ary["request_uid"] = $request_uid;
		$ary["answer_uid"] = $answer_uid;
		$ary["have_get"] = 0;
		$ary["create_time"] = Date::get_date_time();
		$ary["status"] = 1;
		$ary["request_name"] = $request_name;
		$ary["answer_name"] = $answer_name;
		
		
		$ret = $this->insert($this->table_name, $ary);
		if ($ret)
		{
			/*$memcache = mem_cache::get_instance();
			$memcache->delete($key);*/
		}
		else
		{
			return false;
		}


		return $this->get_lastinsertid();
	}
	
		/**
	 * 插入请求数据
	 */
	function update_love_request_by_id($id,$open_id="",$mid="",$content="",$have_get="")
	{
		// 插入数据
		$id = intval($id);
		
		$ary = array();
		if($open_id)
		{
			$ary["open_id"] = $open_id;
		}
		if($content)
		{
			$ary["content"] = $content;
		}
		
		if($mid)
		{
			$ary["mid"] = $mid;
		}
		if($have_get)
		{
			$ary["have_get"] = $have_get;
		}
		
		$where = " id = {$id}";
		
		$ret = $this->update($this->table_name, $ary,$where);
		if ($ret)
		{
			/*$memcache = mem_cache::get_instance();
			$memcache->delete($key);*/
		}
		else
		{
			return false;
		}


		return true;
	}
	
	function del_love_request_by_id($id)
	{
		$ary["status"] = 0;	
		$where = " id = {$id}";
		
		$ret = $this->update($this->table_name, $ary,$where);
		
	}
	
}


?>
